#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QSqlRecord>
 #include <QMessageBox>
 #include <QSqlDatabase>
 #include <QSqlError>
 #include <QSqlQuery>
#include <QSqlTableModel>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->init();
}

MainWindow::~MainWindow()
{
    delete ui;
}
 bool MainWindow::init()
{
    db= QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("concate");
    if(!db.open())
    {

        return false;
    }
    //QSqlQuery query("SELECT name FROM sqlite_master WHERE  name='users' or name='sys'; ");
    //QSqlRecord rec=query.record();

  //  qDebug()<<query.numRowsAffected();
  //  while(query.next())
    //    qDebug()<<query.value(0).toString();
   // qDebug()<<rec.fieldName(0)<<"|"<<rec.fieldName(1)<<"|"<<rec.count();
  //  query.exec("CREATE  TABLE users (id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , name VARCHAR NOT NULL , tel VARCHAR, mobile VARCHAR, part VARCHAR, key VARCHAR)");
    search.exec("select * from users");
    mainmodel.setQuery("SELECT * FROM users",db);
    this->ui->tableView->setModel(&mainmodel);
}


